<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  xmlns:wpf="clr-namespace:MaterialDesignThemes.Wpf;assembly=MaterialDesignThemes.Wpf"
  xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters;assembly=MaterialDesignThemes.Wpf">

  <ResourceDictionary.MergedDictionaries>
    <ResourceDictionary Source="MaterialDesignTheme.Shadows.xaml" />
  </ResourceDictionary.MergedDictionaries>

  <converters:CardClipConverter x:Key="CardClipConverter" />

  <ControlTemplate TargetType="{x:Type wpf:Card}" x:Key="CardTemplate">
    <ControlTemplate.Resources>
      <converters:ShadowEdgeConverter x:Key="ShadowEdgeConverter" />
    </ControlTemplate.Resources>
    <Grid Background="Transparent">
      <AdornerDecorator CacheMode="{Binding RelativeSource={RelativeSource Self}, Path=(wpf:ShadowAssist.CacheMode)}">
        <AdornerDecorator.OpacityMask>
          <MultiBinding Converter="{StaticResource ShadowEdgeConverter}">
            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ActualWidth"/>
            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="ActualHeight"/>
            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:ShadowAssist.ShadowDepth)" />
            <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="(wpf:ShadowAssist.ShadowEdges)" />
          </MultiBinding>
        </AdornerDecorator.OpacityMask>
        <Border Effect="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(wpf:ShadowAssist.ShadowDepth), Converter={x:Static converters:ShadowConverter.Instance}}"
          CornerRadius="{TemplateBinding UniformCornerRadius}">
          <Border Background="{TemplateBinding Background}" Padding="{TemplateBinding Padding}"
            x:Name="PART_ClipBorder"
            Clip="{TemplateBinding ContentClip}" />
          </Border>
        </AdornerDecorator>
        <ContentPresenter
          x:Name="ContentPresenter"
          Margin="{TemplateBinding Padding}"
          Clip="{TemplateBinding ContentClip}"
          Content="{TemplateBinding ContentControl.Content}"
          ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}"
          ContentTemplateSelector="{TemplateBinding ContentControl.ContentTemplateSelector}"
          ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}">
        </ContentPresenter>
      </Grid>
    </ControlTemplate>

    <Style x:Key="MaterialDesignRaisedCard" TargetType="{x:Type wpf:Card}">
      <Setter Property="Template" Value="{StaticResource CardTemplate}" />
      <Setter Property="Background" Value="{DynamicResource MaterialDesignCardBackground}" />
      <Setter Property="VerticalAlignment" Value="Top" />
      <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth2" />
      <Setter Property="Focusable" Value="False"/>
      <Setter Property="UniformCornerRadius" Value="2" />
    </Style>

    <Style x:Key="MaterialDesignLightRaisedCard" TargetType="{x:Type wpf:Card}" BasedOn="{StaticResource MaterialDesignRaisedCard}">
      <Setter Property="Background" Value="{DynamicResource MaterialDesignBackground}" />
      <Setter Property="Padding" Value="8" />
      <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth1" />
    </Style>

    <Style x:Key="MaterialDesignFlatCard" BasedOn="{StaticResource MaterialDesignRaisedCard}" TargetType="{x:Type wpf:Card}">
      <Setter Property="wpf:ShadowAssist.ShadowDepth" Value="Depth0" />
      <Setter Property="UniformCornerRadius" Value="0" />
    </Style>

    <Style x:Key="{x:Type wpf:Card}" BasedOn="{StaticResource MaterialDesignRaisedCard}" TargetType="{x:Type wpf:Card}" />
  </ResourceDictionary>
